<html>
<head><meta charset="utf-8"><title>async-signal-safe issue in process execution · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html">async-signal-safe issue in process execution</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206636035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206636035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206636035">(Aug 11 2020 at 21:57)</a>:</h4>
<p>Could someone take a look at <a href="https://github.com/rust-lang/rust/issues/73894">https://github.com/rust-lang/rust/issues/73894</a> ? There's an async-signal-safety issue, and I think someone with libs experience should take a look at it.</p>



<a name="206640113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206640113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206640113">(Aug 11 2020 at 22:47)</a>:</h4>
<p>I'll ask our glibc folks too</p>



<a name="206643834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206643834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206643834">(Aug 11 2020 at 23:30)</a>:</h4>
<p>I just looked at the implementation of abort in glibc, it looks signal-safe to me.</p>



<a name="206643991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206643991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206643991">(Aug 11 2020 at 23:33)</a>:</h4>
<p>Hmm actually I can see an issue if it's used after <code>fork</code> in a multi-threaded process, it could deadlock itself trying to acquire the recursive lock.</p>



<a name="206644085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206644085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206644085">(Aug 11 2020 at 23:34)</a>:</h4>
<p>Yeah, there's a comment to that effect in the manual sources:</p>
<div class="codehilite"><pre><span></span><code>@deftypefun void abort (void)
@standards<span class="nb">{</span>ISO, stdlib.h<span class="nb">}</span>
@safety<span class="nb">{</span>@prelim<span class="nb">{}</span>@mtsafe<span class="nb">{}</span>@asunsafe<span class="nb">{</span>@asucorrupt<span class="nb">{}}</span>@acunsafe<span class="nb">{</span>@aculock<span class="nb">{}</span> @acucorrupt<span class="nb">{}}}</span>
@c The implementation takes a recursive lock and attempts to support
@c calls from signal handlers, but if we&#39;re in the middle of flushing or
@c using streams, we may encounter them in inconsistent states.
The @code<span class="nb">{</span>abort<span class="nb">}</span> function causes abnormal program termination.  This
does not execute cleanup functions registered with @code<span class="nb">{</span>atexit<span class="nb">}</span> or
@code<span class="nb">{</span>on<span class="nb">_</span>exit<span class="nb">}</span>.
</code></pre></div>



<a name="206644179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206644179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206644179">(Aug 11 2020 at 23:36)</a>:</h4>
<p>(the <code>@c</code> lines)</p>



<a name="206704802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206704802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206704802">(Aug 12 2020 at 14:56)</a>:</h4>
<p>It seems like we should just call the abort intrinsic instead and not worry about whatever the current glibc version is doing. Even if they fix the implementation we're still stuck supporting glibc versions that don't have that for a decade or whatever</p>



<a name="206708969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206708969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206708969">(Aug 12 2020 at 15:25)</a>:</h4>
<p><span class="user-mention" data-user-id="243558">@Steven Fackler</span> the upstream issue said it was just a problem with the docs and it had been async safe for a while</p>



<a name="206709028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206709028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206709028">(Aug 12 2020 at 15:25)</a>:</h4>
<p>Not sure how long 'a while' is though</p>



<a name="206709029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206709029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206709029">(Aug 12 2020 at 15:25)</a>:</h4>
<p>Except that it takes out a lock, right?</p>



<a name="206709126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206709126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206709126">(Aug 12 2020 at 15:26)</a>:</h4>
<p>Ah ok yeah</p>



<a name="206709194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206709194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206709194">(Aug 12 2020 at 15:26)</a>:</h4>
<p>'a while' is 2.27</p>



<a name="206721055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206721055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206721055">(Aug 12 2020 at 16:58)</a>:</h4>
<p>A process dying with a SIGABRT is much more user-friendly than dying with a SIGILL (which is what <code>intrinsics::abort</code> does).</p>



<a name="206722266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206722266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206722266">(Aug 12 2020 at 17:09)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> It is, but a process hitting the rare case where it deadlocks internally or otherwise breaks due to concurrency issues is even less friendly.</p>



<a name="206724289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206724289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206724289">(Aug 12 2020 at 17:25)</a>:</h4>
<p>How would a user ever interact with the child processes if it aborts pre-exec?</p>



<a name="206772093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206772093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206772093">(Aug 13 2020 at 01:21)</a>:</h4>
<p>To get the deadlock you need one thread to abort at the exact same time a <code>fork</code> is happening in another thread. And then you need to have the child process also abort itself.</p>



<a name="206772124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206772124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206772124">(Aug 13 2020 at 01:22)</a>:</h4>
<p>These circumstances are exceedingly rare.</p>



<a name="206798333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206798333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206798333">(Aug 13 2020 at 10:07)</a>:</h4>
<p>still seems like a shame that such failure conditions exist</p>



<a name="206848365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206848365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206848365">(Aug 13 2020 at 17:59)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Most race conditions do tend to be exceedingly rare; that's all the <em>more</em> reason to avoid them, because they also tend to be hard to debug or diagnose.</p>



<a name="206855604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206855604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206855604">(Aug 13 2020 at 18:59)</a>:</h4>
<p>An abort race means you already have bad things going on. Plus only the child can deadlock, so things like supervised restart should still work after the parent death.</p>
<p>So the race failure ultimately just means you'd have a deadlocked orphan that was already trying to die.</p>



<a name="206855991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206855991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206855991">(Aug 13 2020 at 19:02)</a>:</h4>
<p>sometimes programming leads to some colorful sentences</p>



<a name="206903144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/async-signal-safe%20issue%20in%20process%20execution/near/206903144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/async-signal-safe.20issue.20in.20process.20execution.html#206903144">(Aug 14 2020 at 06:48)</a>:</h4>
<p>I'd still argue libc should consider this a bug. for example, they could try_acquire the lock a couple times (is <code>sleep</code> async-signal-safe?), and then SIGILL if they cannot get the lock, basically falling back to a less nice abort.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>